package org.example.two.sort;

import org.example.two.Example;

/**
 * @outher 刘旭
 * @date 2024/5/27 15:41
 */
public class Bubble extends Example {

    @Override
    public void sort(Comparable[] a) {
        int len = a.length;

        for (int i = 0; i < len; i++) {
            int flag = 0;
            for (int j = 0; j < len - 1 - i; j++) {
                if (les(a[j+1],a[j])){
                    exch(a,j,j+1);
                    flag = 1;
                }
            }
            if (flag == 0) {
                break;
            }
        }
    }
}
